<template>
  <div class="visitor-alreadyVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">街路巷(小区):</div>
        <div class="input-item">
          <a-select
            v-model="queryParam.xQfDzbm"
            placeholder="请选择"
            show-search
            :filterOption="filterOption"
            allowClear
            @change="(value) => handleSelectChange(value, 1)"
          >
            <a-select-option v-for="(item, index) in villageList" :key="index" :value="item.fDzbm">
              {{ item.fName }}
            </a-select-option>
          </a-select>
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">建筑物:</div>
        <div class="input-item">
          <a-select
            allowClear
            v-model="queryParam.jzfDzbm"
            placeholder="请选择"
            @change="(value) => handleSelectChange(value, 2)"
          >
            <a-select-option v-for="(item, index) in buildingList" :key="index" :value="item.fDzbm">
              {{ item.fName }}
            </a-select-option>
          </a-select>
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">单元名称 :</div>
        <div class="input-item">
          <a-select
            allowClear
            v-model="queryParam.dyfDzbm"
            placeholder="请选择"
            @change="(value) => handleSelectChange(value, 3)"
          >
            <a-select-option v-for="(item, index) in unitList" :key="index" :value="item.fDzbm">
              {{ item.fName }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">楼层名称:</div>
        <div class="input-item">
          <a-select
            allowClear
            v-model="queryParam.lcfDzbm"
            placeholder="请选择"
            @change="(value) => handleSelectChange(value, 4)"
          >
            <a-select-option v-for="(item, index) in floorList" :key="index" :value="item.fDzbm">
              {{ item.fName }}
            </a-select-option>
          </a-select>
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">房间名称:</div>
        <div class="input-item">
          <a-select allowClear v-model="queryParam.fjfDzbm" placeholder="请选择">
            <a-select-option v-for="(item, index) in roomList" :key="index" :value="item.fDzbm">
              {{ item.fName }}
            </a-select-option>
          </a-select>
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">房屋负责人:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model="queryParam.headName" placeholder="请填写" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">身份证号:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model="queryParam.idCard" placeholder="请填写" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">采集人类型:</div>
        <div class="input-item">
          <a-select allowClear v-model="queryParam.fCjrxmType" placeholder="请选择">
            <a-select-option v-for="(item, index) in collectionPersonalType" :key="index" :value="item.value">
              {{ item.title }}
            </a-select-option>
          </a-select>
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">采集时间 :</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>
      <div class="btn-wrap">
        <a-button class="searchBtn" @click="searchQuery()" type="primary"> 搜索 </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        ref="table"
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="action" slot-scope="records">
          <span class="operation deatil-color" @click="handleDetail(records)">详情</span>
        </template>
      </a-table>
    </div>
    <RentDetail ref="rentDetailRef" />
  </div>
</template>

<script>
import startEndTime from '@/components/startEndTime'
import { JeecgListMixinNew } from '@/mixins/JeecgListMixinNew'
import { getCommunityList, getDictItemsFromCache, getSubordinateList } from '../../../api/api'
import RentDetail from './modules/rentDetail.vue'
import { collectTypeMap, handleSelectChange } from '../../../utils/util'

export default {
  name: 'room',
  components: { startEndTime, RentDetail },
  mixins: [JeecgListMixinNew],
  props: {
    idCode: {
      type: String,
      default: '',
    },
    villageList: {
      type: Array,
      default: () => [],
    },
  },
  watch: {
    idCode(newVal) {
      this.extendParams.policeAgencyId = newVal
    },
  },
  data() {
    return {
      url: {
        list: '/rentinghouse/rentingHouseList',
      },
      publicVisible: false,
      disableMixinCreated: true,
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '街路巷(小区)',
          dataIndex: 'fJlxxqmc',
          ellipsis: true,
          width: 300,
          align: 'center',
        },
        {
          title: '建筑物',
          dataIndex: 'fJzwmc',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '单元',
          dataIndex: 'fDymc',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '楼层',
          dataIndex: 'fLcmc',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '房间',
          dataIndex: 'fShXh',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '房屋负责人',
          dataIndex: 'fFzrXm',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '身份证号',
          dataIndex: 'fFzrIdCard',
          ellipsis: true,
          align: 'center',
          width: 200,
        },
        {
          title: '采集人',
          dataIndex: 'fCjrxm',
          ellipsis: true,
          align: 'center',
          width: 100,
        },
        {
          title: '采集人类型',
          dataIndex: 'fCjrxmType',
          ellipsis: true,
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return collectTypeMap[t]
          },
        },
        {
          title: '采集时间',
          dataIndex: 'createTime',
          ellipsis: true,
          align: 'center',
          width: 200,
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          ellipsis: true,
          align: 'center',
          width: 100,
        },
      ],
      project_company_type: [],
      times: {},
      buildingList: [],
      unitList: [],
      floorList: [],
      roomList: [],
      queryParam: this.initQueryParams(),
      flagTypeList: [],
      extendParams: {
        status: 0,
      },
    }
  },
  computed: {
    collectionPersonalType() {
      return getDictItemsFromCache('collection_personnel_type')
    },
  },
  mounted() {
    this.flagTypeList = getDictItemsFromCache('flag_type')
    this.initPage()
  },
  methods: {
    initQueryParams() {
      return {
        xQfDzbm: undefined,
        jzfDzbm: undefined,
        dyfDzbm: undefined,
        lcfDzbm: undefined,
        fjfDzbm: undefined,
        headName: '',
        idCard: '',
      }
    },
    searchReset() {
      this.queryParam = this.initQueryParams()
      this.buildingList = []
      this.unitList = []
      this.floorList = []
      this.roomList = []
      if (this.resetTime !== undefined) {
        this.resetTime = true
      }
      this.loadData(1)
    },
    handleDetail(records) {
      this.$refs.rentDetailRef.show(records)
    },
    handleSelectChange,
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    searchQuery() {
      if (!this.idCode) {
        this.$message.error('请选择机关信息!')
        return
      }
      const { startTime, endTime } = this.queryParam
      if ((startTime && !endTime) || (!startTime && endTime)) {
        this.$message.error('开始时间结束时间必须同时选择')
        return
      }
      this.loadData(1)
    },
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.startTime = this.$moment(v).valueOf()
        if (v == null) {
          this.queryParam.startTime = null
        }
      } else {
        this.queryParam.endTime = this.$moment(v).valueOf()
        if (v == null) {
          this.queryParam.endTime = null
        }
      }
    },
    async initPage() {
      try {
        console.log(res)
      } catch (error) {
      } finally {
      }
    },
  },
}
</script>
